package com.zzh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzh.controller.utils.R;
import com.zzh.controller.utils.RMsg;
import com.zzh.mapper.VideoMapper;
import com.zzh.ov.PageAndKey;
import com.zzh.ov.VideoInfoAndVideo;
import com.zzh.pojo.Video;
import com.zzh.pojo.VideoInfo;
import com.zzh.service.VideoInfoService;
import com.zzh.mapper.VideoInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Book;
import java.util.HashMap;
import java.util.List;

/**
 *
 */
@Service
@Slf4j
public class VideoInfoServiceImpl extends ServiceImpl<VideoInfoMapper, VideoInfo>
    implements VideoInfoService{
    @Autowired
    private VideoInfoMapper videoInfoMapper;
    @Autowired
    private VideoMapper videoMapper;

    public R getAllVideoAndInfo() {
        List<VideoInfoAndVideo> allVideoAndInfo = videoInfoMapper.getAllVideoAndInfo();
        HashMap<String, Object> hashMap = new HashMap<>();
//        for (VideoInfoAndVideo o :
//                allVideoAndInfo) {
//            hashMap.put()
//        }
        return R.success(allVideoAndInfo);
    }

    @Override
    public R getPage(int page, int size) {
        Page<VideoInfo> infoPage = new Page<>(page,size);
        IPage<VideoInfo> videoInfoPage = videoInfoMapper.selectPage(infoPage, null);
        return R.MyPage(videoInfoPage);
    }

//    @Override
//    public R getPageByKeyWord(int page, int size, String keyWord) {
//        if (page == 0){
//            page = 1;
//        }
//        if (size == 0){
//            size = 5;
//        }
//        Page<VideoInfo> infoPage = new Page<>(page, size);
//        LambdaQueryWrapper<VideoInfo> wrapper = new LambdaQueryWrapper<>();
//        wrapper.like(VideoInfo::getTittle,keyWord);
//        Page<VideoInfo> selectPage = videoInfoMapper.selectPage(infoPage, wrapper);
//        return R.MyPage(selectPage);
//    }
    //根据关键字分页
    public R getPageByKey(PageAndKey pageAndKey) {
        int page = pageAndKey.getPage();
        int size = pageAndKey.getSize();
        if(page == 0 ){
            page = 1;
        }
        if (size == 0){
            size = 5;
        }
        String key = pageAndKey.getKey();
        Page<VideoInfo> infoPage = new Page<>(page, size);
        LambdaQueryWrapper<VideoInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(VideoInfo::getTittle,key);
        Page<VideoInfo> selectPage = videoInfoMapper.selectPage(infoPage, wrapper);
        return R.MyPage(selectPage);
    }

    public R getVideoById(Integer id){
        return R.success(videoInfoMapper.selectById(id));
    }
}




